package test;

import java.sql.*;

public class JDBCDemo {
    public static void main(String[] args) throws SQLException {
        // 1. 加载驱动？？没了？因为jdk升级后大部分驱动包自动加载


        // 2. 创建连接
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/dianshang?useUnicode=true&characterEncoding=utf-8","root", "123456");

        String sql = "SELECT `id`,`phone`,`uname`,`password`,`sex`,`email`,`birthday`,`imgpath`,`cdate`,`lastlogintime` FROM\n" +
                " userinfomst";

        // 3. 创建执行器
        PreparedStatement ps = conn.prepareStatement(sql);

        // 4. 执行SQL处理结果
        ResultSet rs = ps.executeQuery();

        while (rs.next()) {
            System.out.print(rs.getInt(1) + "\t");
            System.out.print(rs.getString("phone")  + "\t");
            System.out.println(rs.getString("password"));
        }


        // 5. 关闭资源
        conn.close();


    }
}
